
CC = gcc
INCLUDE = -I. -I/usr/local/lib/libffi-3.0.9/include -I/usr/local/dao/include
CFLAG = -c -fPIC -DUNIX
LFLAG = 
LFLAG2 = 
LIB = -L/usr/local/lib -lffi

CLOAD = DaoCLoader.so
SAMPLE = sample.so

UNAME = $(shell uname)

ifeq ($(UNAME), Linux)
  CFLAG += -DUNIX
  #INCLUDE += -I/usr/include/mysql
  LFLAG += -fPIC -shared -Wl,-soname,libdaocloader.so
  LFLAG2 += -fPIC -shared -Wl,-soname,sample.so
endif

ifeq ($(UNAME), Darwin)
  CLOAD = DaoCLoader.dylib
  SAMPLE = sample.dylib
  INCLUDE += -Ilibffi-3.0.8/include
  CFLAG += -DUNIX -DMAC_OSX
  LFLAG += -fPIC -dynamiclib -undefined dynamic_lookup -install_name libdaocloader.dylib
  LFLAG2 += -fPIC -dynamiclib -install_name sample.dylib
endif

all: $(CLOAD) $(SAMPLE)

daoCLoader.o: daoCLoader.c
	$(CC) $(CFLAG) $(INCLUDE) daoCLoader.c

$(CLOAD): daoCLoader.o
	$(CC) $(LFLAG) $(LIB) daoCLoader.o -o $(CLOAD)

sample.o: sample.c
	$(CC) $(CFLAG) $(INCLUDE) sample.c

$(SAMPLE): sample.o
	$(CC) $(LFLAG2) $(LIB) sample.o -o $(SAMPLE)

bind: clean

clean:
	rm *.o
